import request from '@/utils/request'
import type { Response, PageDataList } from '@/utils/type'
import type { AxiosResponse } from 'axios'
import type { CountyIndexTable } from '@/api/back-management/composite-analysis/interface'

export interface CompositeAnalysis {
  pkid: string
  year: string
  communityId: string
  createTime: string
  status: string
  updateTime: string
  createUserId: string
  communityName: string
  regionName: string
  streetName: string
}

export interface CompositeListQuery {
  pageIndex: number
  pageSize: number
  startTime: string
  endTime: string
  status: string
  communityName: string
  // communityIds: [];
}

export interface CompositeForm {
  /**
   * 基本公共服务设施完善
   */
  synthesisPublicInfos: CompositeFormItem[]
  /**
   * 便民商业服务设施健全
   */
  synthesisCommerceInfos: CompositeFormItem[]
  /**
   * 市政配套基础设施完备
   */
  synthesisMunicipalInfos: CompositeFormItem[]
  /**
   * 公共活动空间充足
   */
  synthesisActivityInfos: CompositeFormItem[]
  /**
   * 物业管理全覆盖
   */
  synthesisPropertyInfos: CompositeFormItem[]
  /**
   * 社区管理机制健全
   */
  synthesisManageInfos: CompositeFormItem[]
}

export interface CompositeFormItem {
  area: any
  evaluate?: string
  content: any
  number: any
  category?: number
  orderIndex?: any
  pkid?: string
  reportId?: string
  cqCriteria?: number
  gjCriteria?: number
  score?: number
}

/**
 * 综合分析列表
 *
 * @param {any} params 新增参数
 *
 */
export const queryCompositeList = (
  data: object
): Promise<Response<PageDataList<CompositeAnalysis>>> => {
  return request('/residential/synthesis/query', {
    method: 'POST',
    data: data,
  })
}

/**
 * 区县分析列表
 *
 * @param {any} params 新增参数
 *
 */
export const queryCountyList = (
  data: object
): Promise<Response<PageDataList<any>>> => {
  return request('/residential/region/query', {
    method: 'POST',
    data: data,
  })
}

/**
 * 查询综合分析评论表
 *
 * @pkid {string} pkid
 *
 */
export const queryCompositeForm = (
  pkid: string
): Promise<Response<CompositeForm>> => {
  return request(`/residential/synthesis/get?communityId=${pkid}`)
}

/**
 * 更新综合分析评论表
 *
 * @pkids {string} pkids
 *
 */
export const updateCompositeForm = (
  communityId: string
): Promise<Response<string>> => {
  return request(
    `/residential/synthesis/updateByList?communityId=${communityId}`,
    {
      method: 'POST',
    }
  )
}

/**
 * 下载综合分析评论表
 *
 * @params {string[]} communityIds
 *
 */
export const downloadCompositeForm = (
  params: string[]
): Promise<AxiosResponse<Blob>> => {
  return request(`/residential/synthesis/exportCommentExcel`, {
    responseType: 'blob',
    method: 'POST',
    data: params,
  })
}

/**
 * 下载区县建设基础评价表
 *
 * @params {string[]} regionIds
 *
 */
export const downloadCountyBuildForm = (
  regionIds: string
): Promise<Response<CountyIndexTable[]>> => {
  return request(`/residential/region/get`, {
    method: 'POST',
    params: {
      regionIds,
    },
  })
}

/**
 * 下载区县指标表格
 *
 * @params {string[]} communityIds
 *
 */
export const downloadCountyIndex = (
  communityIds: string
): Promise<AxiosResponse<Blob>> => {
  return request(
    `/residential/synthesis/exportIndex?communityIds=${communityIds}`,
    {
      responseType: 'blob',
      method: 'POST',
    }
  )
}

/**
 * 下载社区表格数据
 *
 * @communityId {string} communityId
 *
 */
export const downloadCompositeList = (
  communityIds: object
): Promise<AxiosResponse<Blob>> => {
  return request(`/proposal/community/config/exportExcel`, {
    responseType: 'blob',
    method: 'POST',
    data: communityIds,
  })
}

/**
 * 下载社区空间数据
 *
 * @communityId {string} communityId
 *
 */
export const downloadShpList = (
  communityIds: object
): Promise<AxiosResponse<Blob>> => {
  return request(`/proposal/community/config/exportShp`, {
    responseType: 'blob',
    method: 'POST',
    data: communityIds,
  })
}

/**
 * 通过指标查询
 *
 * @params {any} 指标数组和区域信息
 *
 */
export const queryListByIndex = (
  params: any,
  data: any,
  pageIndex: number,
  pageSize: number
): Promise<Response<any>> => {
  return request(
    `/residential/synthesis/queryByIndex/${pageSize}/${pageIndex}`,
    {
      method: 'POST',
      params,
      data,
    }
  )
}

// exportExcel?

/**
 * 下载社区表格数据
 *
 * @communityId {string} communityId
 *
 */
export const downloadIndexList = (
  params: any,
  data: any
): Promise<AxiosResponse<Blob>> => {
  return request(`/residential/synthesis/exportExcel`, {
    responseType: 'blob',
    method: 'POST',
    params,
    data,
  })
}

/**
 * 下载统计信息
 *
 * @data {any} 请求参数
 *
 */
export const getStatic = (
  data: any
): Promise<
  Response<
    {
      number: number
      classSize: number
      area: number
      bunk: number
      category: number
    }[]
  >
> => {
  return request(`/residential/synthesis/getStatic`, {
    method: 'POST',
    data,
  })
}
